import axios from 'axios'
import request from '@/api/request'

let getUrl = function(url) {
    //ENV_CONFIG: '"dev"',
    if (process.env.ENV_CONFIG == 'dev') {
        ////devApi
        ///用代理
        return '/devApi' + url

    } else {
        return process.env.BASE_API + url;
    }

}
export function downloadFile(fileUrl, fileName) {
    fileName = fileName || 'moban'
    fileUrl = getUrl("/file/down_file/" + fileUrl);
    const link = document.createElement('a');
    link.href = fileUrl;
    link.setAttribute('download', fileName);
    link.click();
}

export function uploadFile(file, filename) {
    let data = new FormData()
    formData.append('file', file);
    let url = '/file/up_file/' + filename
    return request({
        url: url,
        method: 'POST',
        data
    })
}

export function getApiUrl(url) {
    return getUrl(url)
}